package com.wlz.aop.earlyAop;

import com.wlz.aop.Calculate;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author wlz
 * @date 2022-05-28  3:42 下午
 */
public class MainStarter {

	public static void main(String[] args) {
		// 控制粒度到类
//		test();
		// 控制粒度到方法
//		test2();
		// 控制自动配置代理
//		test3();
		// 按正则匹配类
		test4();
	}

	/**
	 *  自定配置代理 按正则匹配类
	 */
	public static void test4() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EarlyAopConfig.class);
		for (String beanDefinitionName : context.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}

		Calculate calculate = context.getBean("myCalculate",Calculate.class);
		calculate.div(1,1);
		System.out.println("-----------------");
		calculate.add(1,2);
	}

	/**
	 *  自定配置代理
	 */
	public static void test3() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EarlyAopConfig.class);
		for (String beanDefinitionName : context.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}

		Calculate calculate = context.getBean("myCalculate",Calculate.class);
		calculate.div(1,1);
		System.out.println("-----------------");
		calculate.add(1,2);
	}


	/**
	 *  粒度到方法
	 */
	public static void test2() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EarlyAopConfig.class);
		for (String beanDefinitionName : context.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}

		Calculate calculate = context.getBean("calculateProxy",Calculate.class);
		calculate.div(1,1);
		System.out.println("-----------------");
		calculate.add(1,2);
	}

	/**
	 *  粒度到类
	 */
	public static void test() {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(EarlyAopConfig.class);
		for (String beanDefinitionName : context.getBeanDefinitionNames()) {
			System.out.println(beanDefinitionName);
		}

		Calculate calculate = context.getBean("calculateProxy",Calculate.class);
		calculate.div(1,1);
		System.out.println("-----------------");
		calculate.add(1,2);
	}
}
